﻿Imports Testeitor.Entidades

Public Class Util

    Public Enum Operacion As Integer
        GUARDAR = 0
        MODIFICAR = 1
        ELIMINAR = 2
    End Enum

    Public Enum TipoEntidad As Integer
        ROL
        USUARIO
        PROYECTO
        PLAN_TEST
        SUITE
        TEST
        ESTADO
        ASIGNACION
        CASO_DE_USO
        RESULTADO_TEST
    End Enum

    Public Enum Prioridad As Integer
        Critica
        Alta
        Media
        Baja
        Trivial
    End Enum

    Public Shared Sub cargarComboEntity(ByRef combo As System.Windows.Forms.ComboBox, ByVal lista As System.Collections.Generic.List(Of Entidades.EntityBase))
        combo.DataSource = lista
    End Sub

    Public Shared Function obtenerEntidad(ByRef lista As System.Collections.Generic.List(Of Entidades.EntityBase)) As Entidades.EntityBase
        Dim index As Integer
        index = TestieitorGui.dgvGrilla.CurrentRow.Index
        obtenerEntidad = lista.Item(index)        
    End Function

    Public Shared Sub mensaje(ByVal mensaje As String, ByVal titulo As String)
        MessageBox.Show(mensaje, titulo, MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Public Shared Sub cargarGrilla(ByVal grilla As DataGridView, ByVal listaColumna As List(Of String), ByVal listaCampos As List(Of String), ByVal listaEntidad As IList)
        grilla.DataSource = Nothing
        For index As Integer = 0 To listaColumna.Count - 1
            Dim columna As DataGridViewTextBoxColumn = New DataGridViewTextBoxColumn
            columna.Name = listaColumna(index)
            columna.HeaderText = listaColumna(index)
            columna.DataPropertyName = listaCampos(index)

            grilla.Columns.Add(columna)
        Next

        grilla.DataSource = listaEntidad
        grilla.Columns("ID").Visible = False
    End Sub

    Public Shared Sub cargarGrilla(ByVal grilla As DataGridView, ByVal listaColumna As List(Of String), ByVal listaCampos As List(Of String))

        For index As Integer = 0 To listaColumna.Count - 1
            Dim columna As DataGridViewTextBoxColumn = New DataGridViewTextBoxColumn
            columna.Name = listaColumna(index)
            columna.HeaderText = listaColumna(index)
            columna.DataPropertyName = listaCampos(index)

            grilla.Columns.Add(columna)
        Next
    End Sub

    Public Shared Function Converteitor(ByVal listaOrigen As IList, ByVal entidad As TipoEntidad) As IList

        Dim listaDestino As IList

        Select Case entidad
            Case TipoEntidad.ROL
                Dim lista As List(Of RolEntity) = New List(Of RolEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, RolEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.USUARIO
                Dim lista As List(Of UsuarioEntity) = New List(Of UsuarioEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, UsuarioEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.PROYECTO
                Dim lista As List(Of ProyectoEntity) = New List(Of ProyectoEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, ProyectoEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.PLAN_TEST
                Dim lista As List(Of PlanTestEntity) = New List(Of PlanTestEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, PlanTestEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.SUITE
                Dim lista As List(Of SuiteEntity) = New List(Of SuiteEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, SuiteEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.TEST
                Dim lista As List(Of TestEntity) = New List(Of TestEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, TestEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.ESTADO
                Dim lista As List(Of EstadoEntity) = New List(Of EstadoEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, EstadoEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.ASIGNACION
                Dim lista As List(Of AsignacionEntity) = New List(Of AsignacionEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, AsignacionEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.CASO_DE_USO
                Dim lista As List(Of CasoDeUsoEntity) = New List(Of CasoDeUsoEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, CasoDeUsoEntity))
                Next
                listaDestino = lista
            Case TipoEntidad.RESULTADO_TEST
                Dim lista As List(Of ResultadoTestEntity) = New List(Of ResultadoTestEntity)
                For Each Item As EntityBase In listaOrigen
                    lista.Add(DirectCast(Item, ResultadoTestEntity))
                Next
                listaDestino = lista
            Case Else
        End Select

        Return listaDestino
    End Function

    Public Shared Sub EnlazarEnumeracionPrioridad(ByRef combo As ComboBox)
        Dim _prioridad As Util.Prioridad
        Dim valores As String() = [Enum].GetNames(_prioridad.GetType())
        For Each item As String In valores
            combo.Items.Add(item)
        Next
    End Sub

    Public Shared Sub CargarCheckedList(ByVal checkedList As CheckedListBox, ByVal lista As IList, ByVal display As String)
        checkedList.DataSource = lista
        checkedList.DisplayMember = display
    End Sub
End Class
